<?php defined('IN_IA') or exit('Access Denied');?><?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/header', TEMPLATE_INCLUDEPATH)) : (include template('common/header', TEMPLATE_INCLUDEPATH));?>
<ul class="nav nav-tabs">
	<li class="active"><a href="<?php  echo $this->createWebUrl('page',array('op' =>'display'))?>">文章管理</a></li>
	<li><a href="<?php  echo $this->createWebUrl('page',array('op' =>'create'))?>">添加文章</a></li>
</ul>
<div class="panel-body">
	<div class="row">
		<div class="col-sm-12 col-md-8">
			<form action="<?php  echo $this->createWebUrl('page')?>" method="post" class="form-inline" role="form">
				<div class="form-group">
					<label>文章搜索</label>
					<input class="form-control" name="keyword" placeholder="请输入文章名称" type="text" value="<?php  echo $keyword;?>"  />
				</div>
				<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
			</form>
		</div>
		<div class="col-sm-12 col-md-4">
			<a class="btn btn-primary pull-right" href="<?php  echo $this->createWebUrl('page',array('op' => 'create'));?>">添加文章</a>
		</div>
	</div>
	<div class="we7-margin-top-sm">
		<table class="table table-bordered we7-form we7-table table-hover vertical-middle">
			<tbody>
				<tr>
					<th style="width:3%;">
						<input type="checkbox" name="check" id="id-0" class="check_all" />
						<label for="id-0">&nbsp;</label>
					</th>
					<th class="text-center" style="width:5%;">文章ID</th>
					<th class="text-center" style="width:15%;">文章名称</th>
					<th class="text-center" style="width:15%;">文章封面</th>
					<th class="text-center" style="width:15%;">作者头像</th>
					<th class="text-center" style="width:15%;">作者昵称</th>
					<th class="text-center" style="width:15%;">发布时间</th>
	                <th class="text-center" style="width:20%;">管理操作</th>
				</tr>
			</tbody>
			<?php  if(is_array($list)) { foreach($list as $row) { ?>
			<tr>
				<td style="overflow:hidden;">
					<input type="checkbox" id="id-<?php  echo $row['page_id'];?>" name="check" value="<?php  echo $row['page_id'];?>" />
					<label for="id-<?php  echo $row['page_id'];?>">&nbsp;</label>
				</td>
				<td class="text-center"><?php  echo $row['page_id'];?></td>
				<td class="text-center"><?php  echo $row['title'];?></td>
				<td class="text-center">
					<img src="<?php  echo $_W['attachurl'];?><?php  echo $row['thumb'];?>" style="width:40px;" />
				</td>
				<td class="text-center">
					<img src="<?php  echo $_W['attachurl'];?><?php  echo $row['avatar'];?>" style="width:40px;" />
				</td>
				<td class="text-center"><?php  echo $row['name'];?></td>
				<td class="text-center"><?php  echo date('Y-m-d H:i',$row["post_time"])?></td>
	            <td class="text-center">
	                <a class="btn btn-default btn-sm" href="<?php  echo $this->createWebUrl('page', array('op' => 'edit', 'id' => $row['page_id']))?>" title="编辑"><i class="fa fa-pencil"></i></a>
	                <a class="btn btn-default btn-sm btn-delete" data-href="<?php  echo $this->createWebUrl('page', array('op' => 'delete', 'id' => $row['page_id']))?>" title="删除"><i class="fa fa-times"></i></a>
	            </td>
			</tr>
			<?php  } } ?>
			<tr>
				<td colspan="6">
					<div class="row">
						<div class="col-xs-12 text-left">
							<input name="batch" type="submit" data-cmd="del" data-text="确认要删除这些文章吗，删除后将不可恢复?" class="btn btn-danger" value="批量删除" />
							<input type="hidden" name="token" value="<?php  echo $_W['token'];?>" />
						</div>
					</div>
				</td>
			</tr>
		</table>
		<?php  if(empty($list)) { ?>
			<span style="margin-left: 45%;">暂无相关数据</span><br />
		<?php  } ?>
		<tr>
			<div class="pull-right"><?php  echo $pager;?></div>
       </tr>
	</div>
</div>
<script>
	$(".check_all").click(function() {
		$("[type='checkbox']").each(function() {
			if($(this).prop("checked")) {
				$(this).attr("checked", false);
				$(".check_all").prop("checked", false);
			} else {
				if($(this).attr("disabled") != "disabled") {
					$(this).prop("checked", true);
					$(".check_all").prop("checked", true);
				}
			}
		});
	});

	// 批量删除
	$("input[name=batch]").click(function() {
		var check = $("input[type=checkbox][class!=check_all]:checked");
		if(check.length < 1) {
			util.message('确认要修改选择要操作的数据！');
			return false;
		}
		var cmd = $(this).data("cmd");
		var text = $(this).data("text");
		util.confirm(function (){
			var id = new Array();
			check.each(function(i) {
				id[i] = $(this).val();
			});
			var url = "<?php  echo $this->createWebUrl('page', array('op' => 'batch'))?>&cmd=" + cmd;
			$.post(url, {
				'idArr': id
			}, function(data) {
				util.message(data.data);
				top.location.reload();
			}, 'json');
		}, function () {
			return false;
		}, text);
	});
	// 单一删除
	$(".btn-delete").click(function(){
		var url = $(this).data("href");
		util.confirm(function () {
			location.href = url;
		}, function () {
			return false;
		}, '删除后该文章不可恢复，确定删除吗?');
	});
</script>
<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/footer', TEMPLATE_INCLUDEPATH)) : (include template('common/footer', TEMPLATE_INCLUDEPATH));?>